package com.ww.springboot.boot.algorithm.leetcode1;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-06-08 11:12
 */
public class CH784字母大小写全排列 {

    public static void main(String[] args) {

        String s = "3z4";
        System.out.println(letterCasePermutation(s));
    }


    /**
     * 回溯
     *
     * @param s
     * @return
     */
    public static List<String> letterCasePermutation(String s) {
        List<String> list = new ArrayList<>();
        letterCasePermutation2("", s, list);
        return list;
    }


    public static void letterCasePermutation2(String sNew, String s, List<String> list) {
        if (sNew.length() == s.length()) {
            list.add(sNew);
            return;
        }
        char c = s.charAt(sNew.length());
        if (Character.isLetter(c)) {
            letterCasePermutation2(sNew + c, s, list);
            if (Character.isLowerCase(c)) {
                letterCasePermutation2(sNew + (char)(c - 32), s, list);
            } else {
                letterCasePermutation2(sNew + (char)(c + 32), s, list);
            }
        } else {
            letterCasePermutation2(sNew + c, s, list);
        }
    }
}
